package org.cloudie.docs.editor.client.widgets;

import org.cloudie.docs.editor.client.commands.Command;
import org.cloudie.docs.editor.client.events.CommandEvent;

import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;

public abstract class ContextMenu extends MenuBar {

  protected ContextMenu() {
    super(true);
    setVisible(false);
  }
  /**
   * Adds a menu item.
   * 
   * @param icon the icon image to use in the menu item
   * @param title the title of the new menu item
   * @param command the command type for the new menu item
   */
  protected void addMenuItem(AbstractImagePrototype icon, String title, final Command command) {
    addMenuItem(icon, title, new com.google.gwt.user.client.Command() {
      public void execute() {
	    CommandEvent.fire(command);
      }
    });
  }
   
  /**
  * Adds a menu item.
  * 
  * @param icon the icon image to use in the menu item
  * @param title the title of the new menu item
  * @param command the command type for the new menu item
  */
  protected void addMenuItem(int index, AbstractImagePrototype icon, String title, final Command command) {
    addMenuItem(index, icon, title, new com.google.gwt.user.client.Command() {
      public void execute() {
	    CommandEvent.fire(command);
      }
    });
  }
  
  protected void addMenuItem(AbstractImagePrototype icon, String title,
      com.google.gwt.user.client.Command command) {
	MenuItem mi = new MenuItem(icon.getHTML() + " " + title, true, command);
    this.addItem(mi);
  }
  
  protected void addMenuItem(int index, AbstractImagePrototype icon, String title,
      com.google.gwt.user.client.Command command) {
	MenuItem mi = new MenuItem(icon.getHTML() + " " + title, true, command);
    this.insertItem(mi, index);
  }
  
  public void hide() {
    setVisible(false);
  }
  
  public void show() {
    setVisible(true);
  }
  
}
